﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Minecraft_Armor_Stand_Creater.Resource.Controls
{
    /// <summary>
    /// MenuBox.xaml 的交互逻辑
    /// </summary>
    public partial class MenuBox : UserControl
    {
        public MenuBox()
        {
            InitializeComponent();
            #region Events
            MouseLeave += CloseSideButtonEvent;

            SideButton.MouseEnter += SideButtonMouseOverEvent;
            SideButton.MouseDown += SideButtonPressedEvent;
            SideButton.MouseLeftButtonUp += SideButtonOverPressedEvent;

            label.MouseLeftButtonDown += OutPut_LeftButtonDown;

            OutPutButton.MouseEnter += OutPutButtonMouseOverEvent;
            OutPutButton.MouseDown += OutPutButtonPressedEvent;
            OutPutButton.MouseLeftButtonUp += OutPutButtonOverPressedEvent;
            OutPutButton.MouseLeave += OutPutButtonMouseLeaveEvent;

            label1.MouseLeftButtonDown += Retrieval_LeftButtonDown;

            RetrievalButton.MouseEnter += RetrievalButtonMouseOverEvent;
            RetrievalButton.MouseDown += RetrievalButtonPressedEvent;
            RetrievalButton.MouseLeftButtonUp += RetrievalButtonOverPressedEvent;
            RetrievalButton.MouseLeave += RetrievalButtonMouseLeaveEvent;
            #endregion
        }

        bool spreadState = false;

        #region Sidebutton
        private void SideButtonPressedEvent(object sender, MouseButtonEventArgs e)
        {
            spreadState = !spreadState;

            VisualStateManager.GoToState(this, "SideButtonPressed", true);
            if (spreadState == false)
            {
                VisualStateManager.GoToState(this, "OutPutButtonUnspread", true);
                VisualStateManager.GoToState(this, "RetrievalButtonUnspread", true);
                OutPutButton.IsHitTestVisible = false;
                RetrievalButton.IsHitTestVisible = false;
            }
            if (spreadState == true)
            {
                VisualStateManager.GoToState(this, "OutPutButtonNormal", true);
                VisualStateManager.GoToState(this, "RetrievalButtonNormal", true);
                OutPutButton.IsHitTestVisible = true;
                RetrievalButton.IsHitTestVisible = true;
            }
        }
        private void SideButtonMouseOverEvent(object sender, MouseEventArgs e)
        {
            VisualStateManager.GoToState(this, "SideButtonMouseOver", true);
        }

        private void SideButtonOverPressedEvent(object sender, MouseButtonEventArgs e)
        {
            VisualStateManager.GoToState(this, "SideButtonMouseOver", true);
        }
        #endregion

        #region OutPutButton
        private void OutPutButtonMouseOverEvent(object sender, MouseEventArgs e)
        {
            VisualStateManager.GoToState(this, "OutPutButtonMouseOver", true);
            label.Foreground = (SolidColorBrush)this.FindResource("CustomBaseColorBrush");
            arc.Fill = new SolidColorBrush(Color.FromRgb(255, 255, 255));
        }

        private void OutPutButtonPressedEvent(object sender, MouseButtonEventArgs e)
        {
            VisualStateManager.GoToState(this, "OutPutButtonPressed", true);
        }

        private void OutPutButtonOverPressedEvent(object sender, MouseButtonEventArgs e)
        {
            VisualStateManager.GoToState(this, "OutPutButtonMouseOver", true);
        }

        private void OutPutButtonMouseLeaveEvent(object sender, MouseEventArgs e)
        {
            VisualStateManager.GoToState(this, "OutPutButtonNormal", true);
            label.Foreground = (SolidColorBrush)this.FindResource("IdealForegroundColorBrush");
            arc.Fill = (SolidColorBrush)this.FindResource("CustomBaseColorBrush");
        }
        #endregion

        #region RetrievalButton
        private void RetrievalButtonPressedEvent(object sender, MouseButtonEventArgs e)
        {
            VisualStateManager.GoToState(this, "RetrievalButtonPressed", true);
        }

        private void RetrievalButtonMouseOverEvent(object sender, MouseEventArgs e)
        {
            VisualStateManager.GoToState(this, "RetrievalButtonMouseOver", true);
            label1.Foreground = (SolidColorBrush)this.FindResource("CustomBaseColorBrush");
            arc1.Fill = new SolidColorBrush(Color.FromRgb(255, 255, 255));
        }

        private void RetrievalButtonMouseLeaveEvent(object sender, MouseEventArgs e)
        {
            VisualStateManager.GoToState(this, "RetrievalButtonNormal", true);
            label1.Foreground = (SolidColorBrush)this.FindResource("IdealForegroundColorBrush");
            arc1.Fill = (SolidColorBrush)this.FindResource("CustomBaseColorBrush");
        }

        private void RetrievalButtonOverPressedEvent(object sender, MouseButtonEventArgs e)
        {
            VisualStateManager.GoToState(this, "RetrievalButtonMouseOver", true);
        }
        #endregion

        private void CloseSideButtonEvent(object sender, MouseEventArgs e)
        {
            spreadState = false;
            OutPutButton.IsHitTestVisible = false;
            RetrievalButton.IsHitTestVisible = false;
            VisualStateManager.GoToState(this, "OutPutButtonUnspread", true);
            VisualStateManager.GoToState(this, "RetrievalButtonUnspread", true);
            VisualStateManager.GoToState(this, "SideButtonNormal", true);
        }

        /// <summary> 输出模式 </summary>
        public bool OutPut { get; set; }
        /// <summary> 检索模式 </summary>
        public bool Retrieval { get; set; }

        private void OutPut_LeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            OutPut = true;
        }

        private void Retrieval_LeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Retrieval = true;
        }
    }
}
